@extends('Admin.layouts.application')
@section('css')
    <link rel="stylesheet" href="/assets/xSystem/vendor/daterangepicker/daterangepicker.css">

@endsection
@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">菜单编辑</strong> /
                    <small>Menu editor</small>
                </div>
            </div>

            <hr>
            @include('Admin.layouts._flash')
            <div class="am-g" style="height: 37px;">
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a type="button" class="am-btn am-btn-success am-btn-xl" href="{{route('hotelreferral.create')}}">
                                <span class="am-icon-plus"></span> 新增信息
                            </a>
                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">

                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>

                                <th class="table-id">ID</th>
                                <th class="table-category">所属菜单</th>
                                <th class="table-category">描述信息</th>
                                {{--<th class="am-hide-sm-only">是否显示</th></th>--}}
                                <th class="am-hide-sm-only">排序</th></th>
                                <th class="table-set">操作</th>

                            </tr>
                            </thead>
                            <tbody>
                            @foreach ($hotelreferrals as $hotelreferral)
                                <tr data-id="{{$hotelreferral->id}}">

                                    <td>{{$hotelreferral->id}}</td>

                                    <td>{{$hotelreferral->category->name or ''}}</td>
                                    <td>{{cut_utf8($hotelreferral->desc,20)}}</td>
                                    {{--@foreach (array('is_show') as $attr)
                                        <td class="am-hide-sm-only">
                                            {!! is_something($attr, $hotelreferral) !!}
                                        </td>
                                    @endforeach--}}
                                    <td class="am-hide-sm-only">
                                        <input  type="text" name="sort_order" class="am-input-sm"
                                                value="{{$hotelreferral->sort_order}}">
                                    </td>

                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                   href="{{route('hotelreferral.edit', $hotelreferral->id)}}">
                                                    <span class="am-icon-pencil-square-o"></span> 编辑
                                                </a>

                                                <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                                   href="{{route('hotelreferral.destroy', $hotelreferral->id)}}"
                                                   data-method="delete"
                                                   data-token="{{csrf_token()}}" data-confirm="确认删除吗?">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                          共{{$hotelreferrals->total()}} 条记录
                        <div class="am-cf">
                            <div class="am-fr">
                               {!! $hotelreferrals->appends(Request::all())->links() !!}
                            </div>
                        </div>
                        <hr/>
                    </form>
                </div>

            </div>
        </div>
        @include('Admin.layouts._footer')

    </div>
@endsection

@section('js')
    <script src="/assets/xSystem/vendor/daterangepicker/moment.js"></script>
    <script src="/assets/xSystem/vendor/moment/locale/zh-cn.js"></script>
    <script src="/assets/xSystem/vendor/daterangepicker/daterangepicker.js"></script>

    <script src="/assets/xSystem/js/daterange_config.js"></script>
    <script>
        //是否...
        $(".is_something").click(function () {
            var _this = $(this);
            var data = {
                id: _this.parents("tr").data('id'),
                attr: _this.data('attr')
            }
            console.log(data);
            $.ajax({
                type: "PATCH",
                url: "/hotelreferral/is_something",
                data: data,
                success: function () {
                    _this.toggleClass('am-icon-close am-icon-check');
                }
            });
        });
        //排序
        $("input[name='sort_order']").change(function () {
            var data = {
                sort_order: $(this).val(),
                id: $(this).parents("tr").data('id')
            };
            console.log(data);
            $.ajax({
                type: "PATCH",
                url: "/hotelreferral/sort_order",
                data: data,
            });
        });
        //删除所选
        $('#destroy_checked').click(function () {
            var length = $(".checked_id:checked").length;
            if (length == 0) {
                alert("您必须至少选中一条!");
                return false;
            }

            var checked_id = $(".checked_id:checked").serialize();
            console.log(checked_id);
            $.ajax({
                type: "DELETE",
                url: "/hotelreferral/destroy_checked",
                data: checked_id,
                success: function () {
                    location.href = location.href;
                }
            });
        });

    </script>




@endsection





